/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View;

import com.sun.lwuit.Button;
import com.sun.lwuit.Component;
import com.sun.lwuit.Dialog;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.Image;
import com.sun.lwuit.Label;
import com.sun.lwuit.animations.CommonTransitions;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.plaf.Border;
import com.sun.lwuit.plaf.Style;
import java.io.IOException;
import testmenu.MainMidlet;

/**
 *
 * @author Windsea
 */
public final class mainMenuForm extends View {

    private Image training_img_unpress = null;
    private Image training_img_press;
    private Image healthtip_img_press;
    private Image healthtip_img_unpress;
    private Image setting_img_press;
    private Image setting_img_unpress, bgimg, title;
    Button btntraining, btntip, btnsetting, btnhelp, btnabout, btnexit;
    private Image help_img_press;
    private Image help_img_unpress;
    private Image about_img_press;
    private Image about_img_unpress;
    private Image exit_img_press;
    private Image exit_img_unpress;
    private Label lbtitle;

    public mainMenuForm(final MainMidlet midlet) {
        super(midlet);
        Display.getInstance().setForceFullScreen(true);
        setTransitionOutAnimator(CommonTransitions.createSlide(
                CommonTransitions.SLIDE_HORIZONTAL, false, 1000));
        try {
            bgimg = Image.createImage("/background.jpg");
            title = Image.createImage("/title.png");
            training_img_unpress = Image.createImage("/training_menu_unpress.png");
            training_img_press = Image.createImage("/training_menu_press.png");
            healthtip_img_press = Image.createImage("/healthtip_menu_press.png");
            healthtip_img_unpress = Image.createImage("/healthtip_menu_unpress.png");
            setting_img_press = Image.createImage("/setting_menu_press.png");
            setting_img_unpress = Image.createImage("/setting_menu_unpress.png");
            help_img_press = Image.createImage("/help_menu_press.png");
            help_img_unpress = Image.createImage("/help_menu_unpress.png");
            about_img_press = Image.createImage("/about_menu_press.png");
            about_img_unpress = Image.createImage("/about_menu_unpress.png");
            exit_img_press = Image.createImage("/exit_menu_press.png");
            exit_img_unpress = Image.createImage("/exit_menu_unpress.png");
        } catch (IOException ex) {
        }
        setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        getStyle().setBgImage(bgimg);
        getStyle().setBackgroundType(Style.BACKGROUND_IMAGE_SCALED);
        Style s4 = new Style();
        s4.setBorder(Border.createEmpty());
        s4.setAlignment(Component.CENTER);
        s4.setBgTransparency(0);
        lbtitle = new Label(title);
        lbtitle.getStyle().setBgTransparency(0);
        btntraining = button_menu(btntraining, training_img_press, training_img_unpress, s4);
        btntip = button_menu(btntip, healthtip_img_press, healthtip_img_unpress, s4);
        btnsetting = button_menu(btnsetting, setting_img_press, setting_img_unpress, s4);
        btnhelp = button_menu(btnhelp, help_img_press, help_img_unpress, s4);
        btnabout = button_menu(btnabout, about_img_press, about_img_unpress, s4);
        btnexit = button_menu(btnexit, exit_img_press, exit_img_unpress, s4);
        addComponent(lbtitle);
        addComponent(btntraining);
        addComponent(btntip);
        addComponent(btnsetting);
        addComponent(btnhelp);
        addComponent(btnabout);
        addComponent(btnexit);

        btntraining.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                Display.getInstance().setForceFullScreen(false);
                if (!midlet.readUserData()) {
                    Dialog.show("Thông báo", "Để sử dụng chức năng này, bạn cần vào mục Setting và điền đầy đủ các thông tin!", "OK", null);
                    System.out.println("false");
                } else {
                    System.out.println("true");
                    //midlet.initTrainingForm();
                    midlet.ShowTrainingForm();
                }
            }
        });
        
        btntip.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                Display.getInstance().setForceFullScreen(false);
                heathtipForm htf = new heathtipForm(midlet);
                htf.show();
                //midlet.showHealthtipForm();
            }
        });
        
        btnsetting.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                Display.getInstance().setForceFullScreen(false);
                midlet.showSettingForm();
            }
        });
        btnhelp.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                Display.getInstance().setForceFullScreen(false);
                listhelp ef = new listhelp(midlet);
                ef.show();
            }
        });
        btnabout.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                Display.getInstance().setForceFullScreen(false);
                AboutForm aboutForm = new AboutForm(midlet);
                aboutForm.show();
            }
        });
        btnexit.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                midlet.destroyApp(true);
            }
        });
    }

    public Button button_menu(Button btn, Image prss, Image unprss, Style style) {
        btn = new Button(unprss);
        btn.setPressedIcon(prss);
        btn.getStyle().setBorder(Border.createEmpty());
//        btn.getStyle().setMargin(20, 20, 20, 20);
//        btn.getStyle().setPadding(20, 20, 15, 15);
        btn.setPressedStyle(style);
        btn.setUnselectedStyle(style);
        return btn;
    }
}
